<?php
require_once("transportations.class.php");
$trans_id = intval( dPgetParam( $_GET, 'trans_id', 0 ) );

// check permissions for this record
/*
$perms =& $AppUI->acl();
if (! ($canEdit = $perms->checkModuleItem( 'currencys', 'edit', $currency_id )) ) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
*/

// load the record data
$msg = '';
$row = new CTransportation();

$canDelete = $row->canDelete( $msg, $currency_id );
if($msg == $AppUI->_('TransportationDeleteUserError', UI_OUTPUT_JS)) {
	$userDeleteProtect=true;
}

if ($view) {
	$view = ' readonly="true"';
}
else {
	unset($view);
}

if (!$row->load( $trans_id ) && $trans_id > 0) {
	$AppUI->setMsg( 'Transportation' );
	$AppUI->setMsg( 'invalidID', UI_MSG_ERROR, true );
	$AppUI->redirect();
}
$status_list=null;
$type_list=null;
$division_list = null;
$costcenter_list = null;
if (!$view) {
require_once(DP_BASE_DIR."/modules/masterdata/mdstatus.class.php");
$status_list = getStatusList($typeTransportation);

require_once(DP_BASE_DIR."/modules/masterdata/mdtype.class.php");
$type_list = getTypeList($typeTransportation);

require_once(DP_BASE_DIR."/modules/masterdata/mddivision.class.php");
$division_list = arrayMerge(array( '' => '' ),getDivisionList());

//$costcenter_list = arrayMerge(array( 0 => '' ),getCostCenterList());

require_once( $AppUI->getModuleClass( 'admin' ) );
$userO = new CUser();
$resource_list = arrayMerge(array( '' => '' ),$userO->getAllowedRecords($AppUI->user_id,'user_id,user_username','user_username'));

$q = new DBQuery();
$q->addTable('transportations');
$q->addQuery('trans_code');
if (isset($row->trans_code)) {
	$q->addWhere("trans_id != $row->trans_id");
}
$quoteCodeList = $q->loadColumn();
$qCL = '["' . implode('", "', $quoteCodeList) . '"]';

?>
<form name="MdTransForm" action="?m=masterdata&u=transportations" method="post">
<input type="hidden" name="dosql" value="do_aed" />
<input type="hidden" name="trans_id" value="<?=$trans_id?>" />
<?}?>
<table border="0" cellpadding="8" cellspacing="0" width="400px">
<tr>
<td colspan="2" bgcolor="#E0E0E0"><b><?=$AppUI->_('Transportation Information')?></td>
</tr>
<tr>
	<td colspan="2">
		<table border="0" cellpadding="0" cellspacing="4" width="100%">
		<tr>
			<td align="right"> * <?=$AppUI->_('Code')?></td>
			<td>
				<input type="text" class="text" name="trans_code" id="trans_code"
				value="<?=@$row->trans_code?>" maxlength="255" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"> * <?=$AppUI->_('Name')?></td>
			<td>
				<input type="text" class="text" name="trans_name" id="trans_name"
					value="<?=@$row->trans_name?>" maxlength="255" style="width:98%" <?=$view?>/>
			</td>
		</tr>
		<? if (!$view) { ?>
		<tr>
			<td align="right">* <?=$AppUI->_('Status')?></td>
			<td>

				<? echo arraySelect($status_list,'trans_status','id="trans_status" size="1" class="text" style="width: 285px"',@$row->trans_status)?>
			</td>
		</tr>
		<tr>
			<td align="right">* <?=$AppUI->_('Type')?></td>
			<td>
				<? echo arraySelect($type_list,'trans_type','id="trans_type" size="1" class="text" style="width: 285px"',@$row->trans_type)?>
			</td>
		</tr>
		<!-- Divisions -->
		<tr>
			<td align="right"><?=$AppUI->_('Division')?></td>
			<td>
				<? /*echo arraySelect($division_list,'trans_division',
									'id="idTransDivisionId" size="1" class="text" style="width: 285px" onchange="doChangeDivision()"',
									@$row->trans_division)*/
					echo arraySelect($division_list,'trans_division','size="1" class="text" style="width: 98%"',@$row->trans_division)
				?>
			</td>
		</tr>
		<!-- costcenter -->
		<tr>
			<td align="right" width="80px"><?=$AppUI->_('Cost Center')?></td>
			<td colspan="3" align="left" nowrap="nowrap">
				<input id="idTransCostCenterName" type="text" class="text" name="trans_costcenter_name"
					value="<?=@$row->getCostCenterName()?>" maxlength="100"
					style="width: <?=$view ? 280 : 260?>px" readonly="true"/>
				<img class="ico clickable" src="images/treetable.gif" onclick="doShowCostCenterSelector()"/>
				<input id="idTransCostCenterId" type='hidden' name='trans_costcenter' value='<?=@$row->trans_costcenter?>'>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Resource')?></td>
			<td>
				<? echo arraySelect($resource_list,'trans_resource','',@$row->trans_resource)?>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Active')?></td>
			<td>
				<input type="checkbox" name="trans_active"
					value="<?=@$row->trans_active?>" maxlength="50" <?=$view?> <?= (@$row->trans_active == 1) ? "checked":""?>/>
			</td>
		</tr>
		<? }else { ?>
		<tr>
			<td align="right"><?=$AppUI->_('Status')?></td>
			<td><? echo @$row->getStatusName();?> </td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Type')?></td>
			<td><? echo @$row->getTypeName();?> </td>
		</tr>
		<? } ?>

		</table>
	</td>
</tr>
<tr>
	<td align="center" colspan="2" style="border-top: 1px solid #E0E0E0">
	<? if (!$view) { ?>
		<input type="submit" class="button" value="<?=$AppUI->_('Save')?>"/>
		<input type="button" class="button" value="<?=$AppUI->_('Cancel')?>" onClick="doCloseTrans()"/>
	<? } else { ?>
		<input type="button" class="button" value="<?=$AppUI->_('Close')?>" onClick="doCloseTrans()"/>
	<? } ?>
	</td>
</tr>
</table>
</form>
<div id="validation_rules" style="visibility: hidden; display: none">
	var fTransCode = new LiveValidation('trans_code');
	fTransCode.add( Validate.Presence );
	fTransCode.add( Validate.Exclusion , {within: <?=$qCL?>});

	var fTransName = new LiveValidation('trans_name');
	fTransName.add( Validate.Presence );

	var fTransstatus = new LiveValidation('trans_status');
	fTransstatus.add( Validate.Presence );

	var fTranstype = new LiveValidation('trans_type');
	fTranstype.add( Validate.Presence );

	new Tips($$('.text'));
</div>